<template>
  <div class="mb-24 w-320px">
    <h1 class="font-bold text-2xl text-center">后台管理系统</h1>
    <el-tabs class="login-panel" type="border-card" v-model="activeTab" stretch>
      <el-tab-pane name="account">
        <template #label>
          <span><i class="el-icon-user"></i> 账户登录</span>
        </template>
        <login-account ref="accountRef" />
      </el-tab-pane>

      <el-tab-pane name="phone">
        <template #label>
          <span><i class="el-icon-mobile-phone"></i> 手机登录</span>
        </template>
        <login-phone />
      </el-tab-pane>
    </el-tabs>

    <div class="flex justify-between">
      <el-checkbox v-model="isRememberPassword" label="记住密码"></el-checkbox>
      <el-link type="primary" :underline="false">忘记密码</el-link>
    </div>
    <el-button type="primary" class="w-full" @click="handleLoginClick"
      >登录
    </el-button>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import LoginAccount from './login-account.vue'
import loginPhone from './login-phone.vue'

const accountRef = ref<InstanceType<typeof LoginAccount>>()
const isRememberPassword = ref(false)
const activeTab = ref('account')

const handleLoginClick = () => {
  //1.账号密码登录
  if (activeTab.value === 'account') {
    accountRef.value?.loginAction(isRememberPassword.value)
  }
  //2.手机号登录
  else {
    console.log(activeTab.value, 'phone login')
  }
}
</script>

<style scoped>
.login-panel {
  width: 320px;
}

.title {
  text-align: center;
}
</style>
